import MyStore from '@/store/index.js'

import config from "@/config"; // 导入配置文件


// 基本路径
const baseURL = config.baseURL;
const token = uni.getStorageSync('token');

export function getDistrictId(adcode) {
	uni.request({
		url: `${baseURL}/district/adcode/${adcode}`,
		method: "GET",
		header: {
			"token": token
		},
		success(res) {
			if (res.data.message === "区域不存在") {
				MyStore.dispatch('setDistrictIdAsync', -1);
			} else {
				MyStore.dispatch('setDistrictIdAsync', res.data.data.id);
			}

		},
		fail(err) {
			uni.showToast({
				title:"服务器罢工了",
				image: '/static/image/icon/Disconnected.png',
				duration:2000
			})
		},
	});
}

